<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>3.app组件</title>
        <!-- 引入Vue -->
        <script src="../js/vue.js"></script>
    </head>
    <body>
        <!-- 准备好一个容器-->
        <div id="app"></div>
    </body>

   

    <script>
        //创建学生组件
        const  Student = Vue.extend({
            template:`
            <div>
                <h1>{{uname}}</h1>
                <h1>{{age}}</h1>
                <h1>{{sex}}</h1>
                <button @click="add">点击+1</button>
            </div>
            `,
            data(){
                return{
                    uname:"张三",
                    age:18,
                    sex:"男"
                }
            },
            methods:{
                add(){
                    this.age ++;
                }
            }
        })


        //创建书籍组件
        const Book = Vue.extend({
            template:`
            <div>
                <h1>{{title}}</h1>
                <h1>{{price}}</h1>
                <button @click="add">奸商涨价了</button>
            </div>
            `,
            data(){
                return{
                    title:"vue从初识到放弃",
                    price:100
                }
            },
            methods:{
                add(){
                    this.price += 100;
                }
            }
        })

        //创建 App 根组件
        const App = Vue.extend({
            template:`
                <div>
                    <Student/>
                    <Book/>
                </div>
            `,
            components:{
                Student,
                Book
            }

        })

        //实例  vm 
        new Vue({
            el:"#app",
            template:`<App/>`,
            components:{
                App
            }
        })

        
    </script>
</html>